package com.hzf.money.rpc.service.impl;

import com.hzf.common.annotation.BaseService;
import com.hzf.money.dao.mapper.MoneyCashFlowMapper;
import com.hzf.money.dao.mapper.MoneyUserMapper;
import com.hzf.money.dao.model.MoneyCashFlow;
import com.hzf.money.dao.model.MoneyCashFlowExample;
import com.hzf.money.dao.model.MoneyUser;
import com.hzf.money.dao.model.MoneyUserExample;
import com.hzf.money.rpc.api.MoneyCashFlowApiService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * describe: TODO
 * creat_user: 白开水
 * creat_time: 2017/12/15   15:52
 **/
@Service
@Transactional
public class MoneyCashFlowApiServiceImpl implements MoneyCashFlowApiService {
    @Autowired
    MoneyCashFlowMapper moneyCashFlowMapper;
    @Autowired
    MoneyUserMapper moneyUserMapper;
    public int instalkOrderCash(MoneyCashFlow moneyCashFlow){
        return  moneyCashFlowMapper.insert(moneyCashFlow);
    }
    public List<MoneyCashFlow> selectAllOrderCash(MoneyCashFlowExample moneyCashFlowExample){
        return moneyCashFlowMapper.selectByExample(moneyCashFlowExample);
    }
    public MoneyCashFlow getMoneyCashFlow(MoneyCashFlowExample moneyCashFlowExample){
        List<MoneyCashFlow> list = moneyCashFlowMapper.selectByExample(moneyCashFlowExample);
        return list.get(0);
    }
    public int updateOrderCash(MoneyCashFlow moneyCashFlow){
        return moneyCashFlowMapper.updateByPrimaryKey(moneyCashFlow);
    }
    public int delectOrderCash(MoneyCashFlowExample moneyCashFlowExample){
        return moneyCashFlowMapper.deleteByExample(moneyCashFlowExample);
    }

    @Override
    public int instalkMoneyUserCash(MoneyUser moneyUser) {
        return moneyUserMapper.insert(moneyUser);
    }

    @Override
    public List<MoneyUser> selectAllMoneyUserCash(MoneyUserExample moneyUserExample) {
        return moneyUserMapper.selectByExample(moneyUserExample);
    }

    @Override
    public MoneyUser getMoneyUserFlow(MoneyUserExample moneyUserExample) {
        List<MoneyUser> moneyUsers = moneyUserMapper.selectByExample(moneyUserExample);
        if(null==moneyUsers||0==moneyUsers.size()){
        return null;
        }
        return moneyUsers.get(0);    }

    @Override
    public int updateMoneyUserCash(MoneyUser moneyUser) {

        return moneyUserMapper.updateByPrimaryKey(moneyUser);
    }

    @Override
    public int delectMoneyCash(MoneyUserExample moneyUserExample) {
        return moneyUserMapper.deleteByExample(moneyUserExample);
    }
}
